/**
 * 
 */
package org.t2.game.server.module.server.service;

import org.gaming.ruler.schedule.AbstractScheduler;
import org.gaming.ruler.schedule.IScheduleTask;
import org.gaming.ruler.schedule.LoopTask;
import org.gaming.tool.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.t2.game.server.module.server.model.ServerInfo;

/**
 * @author YY
 *
 */
@Component
public class ServerTimer extends AbstractScheduler {

	@Autowired
	private ServerInfoService serverInfoService;

	@Override
	protected IScheduleTask[] tasks() {
		ServerInfo serverInfo = serverInfoService.getMain();
		IScheduleTask task1 = new LoopTask(ServerInfoService.ServerOpenTaskName, DateTimeUtil.ONE_SECOND_MILLIS, 0, () -> {
			serverInfoService.runForOpen();
		});
		if (serverInfo.isOpened()) {
			//已经开服后，再次启动服务器时将不再注册开服定时器
			return new IScheduleTask[] {};
		} else {
			return new IScheduleTask[] { task1 };
		}
	}
}
